<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="c-rt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@page import="com.yaodian100.core.common.utils.ServerValue"%>
<c-rt:set var="midContextPath" value='<%=ServerValue.getMidContextPath() %>'/>
<c-rt:set var="midHostname" value='<%=ServerValue.getMidHostname()%>'/>
<!-- 月历 -->
<script type="text/javascript" charset="UTF-8" src="/js/jquery.datepick.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/jquery.datepick-zh-CN.js"></script>
<link rel="stylesheet" type="text/css" href="/css/smoothness.datepick.css" />
<!-- 数字验证 -->
<script type="text/javascript" charset="UTF-8" src="/js/jquery.alphanumeric.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/jquery.autotab-1.1b.js"></script>
<!-- FLASH -->
<script type="text/javascript" charset="UTF-8" src="/js/jquery.flash.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/yaodian100.common.js"></script>
<style type="text/css">
.msg{float:left; line-height:1em; margin:0; display:block;border:1px solid #f66;padding:2px 5px;*padding:2px 5px 1px;}
.msg.rn{background-color:#fff2f2;border-color:#f66;}
</style>

<s:set name="imageHeightLimit" value="%{imageHeightLimit}" ></s:set>
<s:set name="imageWidthLimit" value="%{imageWidthLimit}" ></s:set>
<s:set name="fileSizeLimitK" value="%{fileSizeLimitK}" ></s:set>
<s:set name="advTypeName" value="%{idxAdvTypeMenu.options[adv.advType].name}"></s:set>

<s:if test="!creatingNew">
	<script language="javascript">
		var imageHeightLimit = ${imageHeightLimit};
		var imageWidthLimit = ${imageWidthLimit};
		var fileSizeLimitK = ${fileSizeLimitK};
		
		$().ready( function() {
			$("#objId").html("<img src='${midHostname}/eventImg/" + $("#idxImgFolder").val() + "/" + $("#advType").val() + "/" + $("#idxImgName").val() + "' width='" + imageWidthLimit + "' height='" + imageHeightLimit + "'/><br/>");
		});
	</script>
</s:if>

<script language="javascript">
	$().ready( function() {
		
		document.title = document.title + " ${advTypeName}";
		
		$('#startDate').datepick({minDate: new Date(), showOn:'both',numberOfMonths:2, buttonImageOnly: true, buttonImage: '/images/calendar.gif',dateFormat:"yy-mm-dd"}); 
		$('#endDate').datepick({minDate: new Date(),showOn: 'both',numberOfMonths:2, buttonImageOnly: true, buttonImage: '/images/calendar.gif',dateFormat:"yy-mm-dd"});

		var imageHeightLimit = ${imageHeightLimit};
		var imageWidthLimit = ${imageWidthLimit};
		var fileSizeLimitK = ${fileSizeLimitK};
		var imageFileCorrectMessageHolder = $("#imageFileCorrect");
		$("#imageFile").change(
			function(){
				checkImg(this, fileSizeLimitK, imageWidthLimit, imageHeightLimit, imageFileCorrectMessageHolder, "");
			}
		);

		$("#subBtn").click(function(){
			if ( validate_data() ){
				$("#advStatus").val("10");
				$("#mainForm").submit();
			}
		});

		$("#draftBtn").click(function(){
			if ( validate_data() ){
				$("#advStatus").val("00");
				$("#mainForm").submit();
			}
		});
		
		$("#canBtn").click(function(){
			if ( validate_data() ){
				$("#advStatus").val("90");
				$("#mainForm").submit();
			}
		});
		
		//限填英數字
		$("#adCode").alphanumeric();
		$("#adCode").autotab_filter({ format: 'custom', pattern: '[^a-zA-Z0-9]' });
		
		$("#clearImg").click(function(event){
			event.preventDefault();
			$("#imageFile").val("");
			$("#imageFileCorrect").val("");
		});
	});
	
	function validate_data(){
		var imageFileCorrectMark = $("#imageFileCorrect");
		
		if ( $("#advName").val() == "" ){
			alert("请输入广告名称");
			$("#advName").focus();
			return false;
		}
		
		if ( $("#startDate").val() == ""){
				alert("请输入起始时间");
				$("#startDate").focus();
				return false;
		}
		if( $("#endDate").val() == "" ){
				alert("请输入结束时间");
				$("#endDate").focus();
				return false;
		}
		if ($("#startDate").val() + $("#startTime").val() >= $("#endDate").val() + $("#endTime").val()) {
			alert("起始时间必须早於结束时间");
			$("#endDate").focus();
			return false;
		}
		
		if ( $("#advId").val() == "" && $('#doClone').val() != 'true' ){
			//新增
			if ($("#imageFile").val() != ""){
				var checkResultMessage = imageFileCorrectMark.val();
				if (checkResultMessage != '') {
					alert(checkResultMessage);
					return false;
				}
			} else {
				alert("请选择图片档案");
				$("idxImg").focus();
				return false;
			}
		} else {
			//編輯
			if ($("#imageFile").val() != ""){
				var checkResultMessage = imageFileCorrectMark.val();
				if (checkResultMessage != '') {
					alert(checkResultMessage);
					return false;
				}
			}
		}
		
		if ( $("#idxImgLink").val() == "" ){
			alert("请输入图片点击连结");
			$("#idxImgLink").focus();
			return false;
		}
		if ( !isURL($("#idxImgLink").val()) ){
			alert("图片点击连结格式错误");
			$("#idxImgLink").focus();
			return false;
		}

		return true;
	}
	
</script>

<h1>
	广告管理 - ${advTypeName}
	<br/>
	<div class="f-link">
		<s:if test="from == 'V5'">
		<a href="${midContextPath}/generate/idxV5/searchIdx.do">回广告查询页</a>
		</s:if>
		<s:elseif test="from == 'PCL'">
		<a href="${midContextPath}/generate/idxV5/searchPcl.do">回广告查询页</a>
		</s:elseif>
		<s:else>
		<a href="${midContextPath}/generate/searchIdx.do">回广告查询页</a>
		</s:else>
	</div>	
</h1>

<s:if test="hasErrors()">
	<s:actionerror cssClass="msg rn" />
</s:if>
<s:if test="hasActionMessages()">
	<s:actionmessage cssClass="msg rn" />
</s:if>
<s:form action="idxImageAdv/saveIdxImageAdv.do" method="post" name="mainForm" id="mainForm" enctype="multipart/form-data">
	<table class="tb-data" width="100%">
		<tbody>
			<tr>
				<th>类型</th>
				<td>
					${advTypeName}
					<s:hidden name="adv.advType" id="advType"></s:hidden>
				</td>
			</tr>
			<tr>
				<th>广告名称</th>
				<td>
					<s:textfield name="adv.advName" id="advName" size="30" maxlength="30" ></s:textfield>
					<s:if test="null != fieldErrors['idxImageAdv.name']">
						<br/>
						<span class="msg rn"><s:fielderror><s:param>idxImageAdv.name</s:param></s:fielderror></span>
					</s:if>
				</td>
			</tr>
			<tr>
				<th>起迄时间</th>
				<td>
					<s:textfield name="idxImageAdv.startDate" id="startDate" maxlength="10" ></s:textfield>
					<select id="startTime" name="idxImageAdv.startTime">			
						<c-rt:forEach begin="0" end="23" var="t1">
							<c-rt:if test="${t1<10}">
							<c-rt:set value="0${t1}:00" var="sTime"></c-rt:set>
							</c-rt:if>
							<c-rt:if test="${t1>=10}">
							<c-rt:set value="${t1}:00" var="sTime"></c-rt:set>
							</c-rt:if>
							<option value="${sTime}" <c-rt:if test="${sTime==idxImageAdv.startTime}">selected</c-rt:if>>${sTime}</option>
						</c-rt:forEach>
					</select>  
					~ 
					<s:textfield name="idxImageAdv.endDate" id="endDate" maxlength="10" ></s:textfield>
					<select id="endTime" name="idxImageAdv.endTime">
					<c-rt:forEach begin="0" end="23" var="t2" >
						<c-rt:set var="t3">${23-t2}</c-rt:set>	
						<c-rt:if test="${t3<10}">
						<c-rt:set value="0${t3}:59" var="eTime"></c-rt:set>
						</c-rt:if>
						<c-rt:if test="${t3>=10}">
						<c-rt:set value="${t3}:59" var="eTime"></c-rt:set>
						</c-rt:if>
						<option value="${eTime}" <c-rt:if test="${eTime==idxImageAdv.endTime }">selected</c-rt:if>>${eTime}</option>
					</c-rt:forEach>
					</select>
					<s:if test="null != fieldErrors['idxImageAdv.startTime']">
						<br/>
							<span class="msg rn">
								<s:fielderror>
									<s:param>idxImageAdv.startTime</s:param>
								</s:fielderror>
							</span>
					</s:if>
					<s:if test="null != fieldErrors['idxImageAdv.endTime']">
							<span class="msg rn">
								<s:fielderror>
									<s:param>idxImageAdv.endTime</s:param>
								</s:fielderror>
							</span>
					</s:if>
				</td>
			</tr>
			<tr>
				<th>图檔设定</th>
				<td>
					<div id="objId">
					</div>
					<br/>
												
					<b>上传图片：</b>
					<s:file id="imageFile" name="idxImageAdv.imageFile" value="" size="60" ></s:file>
					<input type="button" value="清除图檔" id="clearImg" />
					<s:hidden id="imageFileCorrect" ></s:hidden>
					<s:if test="null != fieldErrors['idxImageAdv.imageFile']">
						<br/>
						<s:fielderror cssClass="msg rn" >
							<s:param>idxImageAdv.imageFile</s:param>
						</s:fielderror>
						<br/>
					</s:if>
					<br/>
						&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						图片规格：${imageWidthLimit}x${imageHeightLimit}&lt;${fileSizeLimitK}k
					<br/>
								
					<b>图片链结：</b>
					<s:textfield name="idxImageAdv.imageLink" id="idxImgLink" size="60" ></s:textfield>
					<br/>
						&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						例如：http://www.yaodian100.com
					<br/>
					<s:if test="null != fieldErrors['idxImgLink']">
						<p><span class="msg rn"><s:fielderror><s:param>idxImgLink</s:param></s:fielderror></span></p>
					</s:if>
					
					<b>广告代码：</b>
					<s:textfield name="idxImageAdv.adCode" id="adCode" size="25" maxLength="25" ></s:textfield>
					<br/>
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					非必填。由英文字母、数字组成，最多25个半角
					
					<s:hidden id="idxImgName" name="idxImageAdv.savedImageFileName" ></s:hidden>
					<s:hidden id="idxImgFolder" name="idxImageAdv.savedImageFolderName" ></s:hidden>
					<s:hidden name="creatingNew"></s:hidden>
				</td>
			</tr>
		<c-rt:if test="${not empty adv.id}">
			<tr>
				<th>修改记录</th>
				<td>
					<p>建立：<fmt:formatDate value="${adv.createDate}" pattern="yyyy-MM-dd HH:mm"/> / ${adv.createUser}</p>
					<p>修改：<fmt:formatDate value="${adv.modifyDate}" pattern="yyyy-MM-dd HH:mm"/> / ${adv.modifyUser}</p>
				</td>
			</tr>
		</c-rt:if>
			<tr>
				<td colspan="2">
					<s:hidden name="adv.id" id="advId" ></s:hidden>
					<s:hidden name="adv.advStatus" id="advStatus" ></s:hidden>
					<input type="hidden" id="from" name="from" value="${from}"/>
					<s:hidden id="doClone" name="doClone" />
					<input type="button" id="subBtn" name="subBtn" value="发送"/>
<!-- 					<input type="button" id="draftBtn" name="draftBtn" value="草稿"/> -->
					<input type="button" id="canBtn" name="canBtn" value="暂停"/>
				</td>
			</tr>												
		</tbody>
	</table>
</s:form>
<div class="f-link">
<s:if test="from == 'V5'">
<a href="${midContextPath}/generate/idxV5/searchIdx.do">回广告查询页</a>
</s:if>
<s:elseif test="from == 'PCL'">
<a href="${midContextPath}/generate/idxV5/searchPcl.do">回广告查询页</a>
</s:elseif>
<s:else>
<a href="${midContextPath}/generate/searchIdx.do">回广告查询页</a>
</s:else>
</div>